<template>
	<view class="content">
		<tabbar class="tabbar" :dataArray="dataArray" :checkedIndex="checkedIndex" @handleIndexChange="typeChange">
		</tabbar>
		<scroll-view scroll-y="true" class="scroll" v-if="checkedIndex==0">
			<activity v-for="(item,index) in actList" @goTo="goTo(arguments)" :id="item.id" :img="item.img"
				:showStatus="true" :state="item.state" :title="item.title" :dateString="item.startDate"
				:location="item.location">
			</activity>
			<!-- <activity :id="1" @goTo="goTo(arguments)" :img="'../../static/石墨镌华——铜镜拓印体验   16 9.jpg'"
				:title="'石墨镌华——铜镜拓印体验'" :dateString="'2021年8月21日'" :location="'盐城市博物馆'">
			</activity>
			<activity :id="2" @goTo="goTo(arguments)" :img="'../../static/熏香染袂   16 9.jpg'" :title="'熏香染袂—香纂、香丸制作'"
				:dateString="'2021年8月21日'" :location="'盐城市博物馆'">
			</activity>
			<activity :id="3" @goTo="goTo(arguments)" :img="'../../static/操缦遗音—古琴展演及体验   16 9.jpg'"
				:title="'操缦遗音—古琴展演及体验'" :dateString="'2021年8月21日'" :location="'盐城市博物馆'">
			</activity>
			<activity :id="4" @goTo="goTo(arguments)" :img="'../../static/青瓯瀹茗—宋式点茶、斗茶     16 9.jpg'"
				:title="'青瓯瀹茗——宋式点茶、斗茶'" :dateString="'2021年8月21日'" :location="'盐城市博物馆'">
			</activity>
			<activity :id="5" @goTo="goTo(arguments)" :img="'../../static/子慕予裳   16 9.jpg'" :title="'子慕予裳——汉服体验'"
				:dateString="'2021年8月21日'" :location="'盐城市博物馆'">
			</activity>
			<activity :id="6" @goTo="goTo(arguments)" :img="'../../static/美人云鬓——花簪制作     16 9.jpg'"
				:title="'美人云鬓——花簪制作'" :dateString="'2021年8月21日'" :location="'盐城市博物馆'">
			</activity> -->
		</scroll-view>
		<scroll-view scroll-y="true" class="scroll" v-if="checkedIndex==1">
		</scroll-view>
	</view>
</template>

<script>
	import {
		dateToString
	} from '../../js_sdk/date-parse/date-parser.js'
	import {
		doPostForm
	} from '../../js_sdk/request-helper.js'
	import activity from "../customer/activity.vue"
	import tabbar from "../customer/tabbar.vue"
	export default {
		components: {
			activity,
			tabbar
		},
		data() {
			return {
				pages: 0,
				size: 8,
				checkedIndex: 0,
				dataArray: [
					"社教活动",
					"讲座",
				],
				actList: []
			}
		},
		onLoad(options) {
			if (options.index) {
				this.pages = 0
				this.checkedIndex = options.index
				this.getList()
			} else {
				this.pages = 0
				this.checkedIndex = 0
				this.getList()
			}
		},
		methods: {
			getList() {
				doPostForm('/blade-museum/act/list', {
					pages: this.pages,
					size: this.size,
					typeCode: this.checkedIndex == 0 ? 3 : 4,
					auditState: true,
					museumId: uni.getStorageSync('museumId')
				}, (res) => {
					let list = []
					for (let item of res.records) {
						item.startDate = dateToString(new Date(item.startTime.replace(/-/g, '/')), 'yyyy年MM月dd日')
						if (new Date().getTime() < new Date(item.startTime.replace(/-/g, '/')).getTime()) {
							item.state = 0
						} else if (new Date().getTime() < new Date(item.endTime.replace(/-/g, '/')).getTime()) {
							item.state = 1
						} else {
							item.state = 2
						}
						list.push(item)
					}
					this.actList = list
				}, (err) => {})
			},
			typeChange(index) {
				this.pages = 0
				this.checkedIndex = index
				this.getList()
			},
			goTo(e) {
				if (typeof e == 'object') {
					if (e[0] == 'notification') {
						uni.navigateTo({
							url: "../notification/notification"
						})
					} else if (e[0] == 'activity') {
						uni.navigateTo({
							url: "../activity/activityList"
						})
					} else if (e[0] == 'activityInfo') {
						uni.navigateTo({
							url: "../activity/activityInfomation?id=" + e[1]
						})
					}
				}
			}
		}
	}
</script>

<style>
	.content {
		position: fixed;
		height: calc(100% - 88rpx);
		width: 100%;
	}

	.scroll {
		height: calc(100% - 80rpx);
		width: 100%;
	}
</style>
